<?php
namespace app\common\model;

class OrderDetails extends Base
{
    protected $resultSetType = 'collection';

    /**
     * 查询订单商品
     * @return [type] [description]
     */
    public function getDatas($where=[],$field=''){
        $data = $this->where($where)->field($field)->select();
        foreach($data as &$row):
            $row = $this->setRemark($row);
        endforeach;
        return $data;
    }

    /**
     * 处理字段数据
     * @param [type] $row [description]
     */
    public function setRemark($row){
        if(isset($row['gid'])){
             $data = model('MallGoods')->getOneDataById($row['gid'],'title,coin_id,cate_id,price,photo');
             $row['title']= $data['title'];
             $row['coin_name']= $data['coin_name'];
             $row['coin_id']= $data['coin_id'];
             $row['cate_name']= $data['cate_name'];
             $row['cate_id']= $data['cate_id'];
             $row['photo']= $data['photo'];
             $row['title']= $data['title'];
        }
        return $row;
    }

    public function add($data=[]){
        return $this->save($data);
    }

    public function del($data=[]){
        return $this->where($data)->delete();
    }

}
